<template>
  <div class="home" v-loading="loading">
    <navbar
      :imgss="userimg"
      :username="username"
      :leave="leave"
      :fs="fs"
      :gz="gz"
    ></navbar>
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
      <jk></jk>
    <footers></footers>
  </div>
</template>

<script>
import navbar from "../components/navbar.vue";
import footers from "../components/footers.vue";
import home2 from "../views/home2.vue";
import { detail } from "../api/user/user";

export default {
  components: { navbar, footers, home2 },
  data: () => {
    return {
      time: "",
      loading: true,
      userimg: "",
      username: "",
      leave: 0,
      gz: 0,
      fs: 0,
    };
  },
  mounted() {
    this.$nextTick(function () {
      let v = JSON.parse(window[this.$store.state._storageUrl].getItem("user"));
      if (v) {
        this.userimg = v.profile.avatarUrl;
        this.username = v.profile.nickname;
        this.details(v);
      } else {
        this.time = setInterval(() => {
          let c = JSON.parse(window.sessionStorage.getItem("user"));
          if (c) {
            console.log(2);
            clearInterval(this.time);
            this.userimg = c.profile.avatarUrl;
            this.username = c.profile.nickname;
            this.details(c);
          }
        }, 100);
      }
    });
  },
  methods: {
    details(v) {
      detail({ uid: v.profile.userId }).then((v) => {
        this.$store.dispatch("user", v);
        this.leave = v.level;
        this.fs = v.profile.followeds;
        this.gz = v.profile.newFollows;
        this.loading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
}
</style>